import { SlateRange,   SlateTransforms } from "@wangeditor/editor";
import { message } from "ant-design-vue";
import BaseFn from "../base-fn";
// import { emitter } from '@/event-bus';
import {  handleUnwrapNodes }  from "../../coreComponents/helper";
class PinyinFn extends BaseFn {
    constructor(editor) {
        super(editor);
    }

    getValue() {
        return super.getValue();
    }

    isDisabled() {
        if (super.isDisabled()) return true;
        return false;
    }
    exec(opt) {
        console.log("ssml-mark:", opt)
        this.editor.restoreSelection();
        if (this.isDisabled()) return;
        SlateTransforms.select(this.editor, opt.selection);
        const value = this.getValue();
        if (value == null) return;
        
        const node = {
            type: "ssml-mark",
            alphabet: "py",
            ph: opt.pyList,
            remark: false,
            children: [{ text: value }],
        };

        this.editor.insertNode(node);
    }

    execUnwrapNodes(path) {
        SlateTransforms.unwrapNodes(this.editor, { at: path }); 
        // handleUnwrapNodes(this.editor, elem)
    }
}

export default PinyinFn;
